<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>畅购商城</title>
    <meta name="description" content="畅购商城">
    <meta name="keywords" content="畅购商城">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <script src="../plugins/healthmobile.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>商品管理
            <small>商品管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>商品管理</el-breadcrumb-item>
            <!--<el-breadcrumb-item>检查项管理</el-breadcrumb-item>-->
        </el-breadcrumb>
    </div>
    <!-- Unnamed (Rectangle) -->
    <div id="u1382" class="ax_default _默认样式">
        <div id="u1382_div" class=""></div>
        <div id="u1382_text" class="text ">
            <p style="font-size:18px;"><span style="font-family:'FontAwesome';font-weight:400;"> </span><span
                    style="font-family:'ArialMT', 'Arial';font-weight:400;font-size:12px;"> </span><span
                    style="font-family:'微软雅黑';font-weight:400;font-size:12px;">筛选查询</span></p>
        </div>
        <div class="app-container">
            <div class="box">
                <div class="filter-container">
                    <span>输入搜索</span>
                    <el-input placeholder="商品编号" v-model="pagination.queryString" style="width: 200px;"
                              class="filter-item"></el-input>
                    <el-button @click="findPage1()" class="dalfBut">查询</el-button>
                    <el-input placeholder="SPUID" v-model="pagination.querySPUID" style="width: 200px;"
                              class="filter-item"></el-input>
                    <el-button @click="findPage1()" class="dalfBut">查询</el-button>
                    <el-input placeholder="商品品牌" v-model="pagination.queryBrandName" style="width: 200px;"
                              class="filter-item"></el-input>
                    <el-button @click="findPage1()" class="dalfBut">查询</el-button>

                    <el-button type="primary" class="butT" @click="handleCreate()">添加</el-button>
                </div>
                <!-- Unnamed (Rectangle) -->
                <div id="u1385" class="ax_default _默认样式">
                    <div id="u1385_div" class=""></div>
                    <div id="u1385_text" class="text ">
                        <p style="font-size:18px;"><span
                                style="font-family:'FontAwesome';font-weight:400;"></span><span
                                style="font-family:'ArialMT', 'Arial';font-weight:400;font-size:12px;"> </span><span
                                style="font-family:'微软雅黑';font-weight:400;font-size:12px;">数据列表</span></p>
                    </div>
                </div>
                <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                    <el-table-column prop="id" label="编号" align="center"></el-table-column>
                    <el-table-column label="商品图片">
                        <template slot-scope="scope">
                            　　　　<img :src="scope.row.image" width="60" height="60" class="head_pic"/>
                        </template>
                    </el-table-column>
                    <!--<el-input v-model="formData.num" placeholder="库存"></el-input>-->
                    <el-table-column prop="num" label="库存" align="center"></el-table-column>
                    <el-table-column prop="alertNum" label="库存预警数量" align="center"></el-table-column>
                    <!--<el-table-column prop="weight" label="重量" align="center"></el-table-column>-->
                    <el-table-column prop="spuId" label="SPUID" align="center"></el-table-column>
                    <el-table-column prop="categoryId" label="类目ID" align="center"></el-table-column>
                    <el-table-column prop="categoryName" label="类目名称" align="center"></el-table-column>
                    <el-table-column prop="brandName" label="品牌名称" align="center"></el-table-column>
                    <el-table-column prop="spec" label="规格" align="center"></el-table-column>
                    <el-table-column prop="saleNum" label="销量" align="center"></el-table-column>
                    <!--<el-table-column prop="commentnNum" label="评论数" align="center"></el-table-column>-->

                    <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button type="primary" size="mini" @click=" handleDetils(scope.row)">编辑</el-button>
                            <!--<el-button type="primary" size="mini" @click=" handleCreate()">添加</el-button>-->
                            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination-container">
                    <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                    </el-pagination>
                </div>
                <div class="details-form">
                    <el-dialog title="商品详情" :visible.sync="dialogFormVisible4Edit">
                        <template>
                            <el-tabs v-model="activeName" type="card">
                                <el-tab-pane label="基本信息" name="first">
                                    <el-form ref="dataAddForm" label-position="right" label-width="100px">
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="编号">
                                                    <el-input v-model="formData.id"/>
                                                </el-form-item>
                                                <el-form-item label="库存">
                                                    <el-input v-model="formData.num"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="SPUID">
                                                    <el-input v-model="formData.spuId"/>
                                                </el-form-item>
                                                <el-form-item label="类目名称">
                                                    <el-input v-model="formData.categoryName"/>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="品牌名称">
                                                    <el-input v-model="formData.brandName"/>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="规格">
                                                    <el-input v-model="formData.spec"
                                                              type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="库存预警量">
                                                    <el-input v-model="formData.alertNum"
                                                              placeholder="请输入内容"></el-input>
                                                    <!--<el-input v-model="formData.alertNum"-->
                                                    <!--type="textarea"></el-input>-->
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                    </el-form>
                                </el-tab-pane>
                            </el-tabs>
                        </template>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                            <el-button type="primary" @click="handleEdit()">确定</el-button>
                        </div>
                    </el-dialog>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null,//查询条件
                queryBrandName:null,
                querySPUID:null,
            },
            activeName: 'first',
            imageUrl: null,
            dataList: [],//当前页要展示的分页列表数据
            tableData: {},
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //添加
            handleAdd() {
                //发送异步请求
                axios.post("/findGoods/add", this.formData).then((resp) => {
                    if (resp.data.flag) {
                        this.$message.success(resp.data.message)
                    } else {
                        this.$message.error(resp.data.message)
                    }
                }).finally(() => {
                        this.dialogFormVisible = false;
                        this.findPage()
                    }
                )
            },
            findPage1() {
                this.pagination.currentPage = 1;
                this.findPage()
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    id: this.pagination.queryString,
                    spuId: this.pagination.querySPUID,
                    brandName: this.pagination.queryBrandName,

                };
                axios.post("/findSKu/findPage/" + this.pagination.currentPage + "/" + this.pagination.pageSize, param
                ).then((resp) => {
                    this.dataList = resp.data.data.rows;
                    this.pagination.total = resp.data.data.total
                })
            },
            // // 重置表单
            resetForm() {
                this.formData = {}
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm()
            },
            // 弹出详情窗口
            handleEdit() {
                this.dialogFormVisible4Edit = false;
                axios.post("/findSKu/updete", this.formData).then((resp) => {
                    if (resp.data.flag) {
                        this.$message.success(resp.data.message)
                        this.findPage();
                    } else {
                        this.$message.error(resp.data.message)

                    }
                })
            },
            handleDetils(row) {
                this.dialogFormVisible4Edit = true;
                axios.get("/findSKu/findSkuById?id=" + row.id).then((response) => {
                    if (response.data.flag) {
                        this.formData = response.data.data;
                        this.imageUrl = response.data.data.image;
                        //查询sku信息
                        // axios.get("/findSKu/findSkuById?id=" + row.id).then((response) => {
                        //     if (response.data.flag) {
                        //         this.tableData = response.data.data;
                        //     }
                        // })
                    }
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage()
            },
            // 删除
            handleDelete(row) {
                this.$confirm('是否删除该商品, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    axios.get("/findSKu/delete?id=" + row.id).then((resp) => {
                        // var __this = this;
                        if (resp.data.flag) {
                            this.$message.success(resp.data.message);
                            this.findPage()
                        } else {
                            this.$message.error(resp.data.message)
                            this.findPage();
                        }
                    })
                })
            },

            //商品上下架
            changeStatus(row) {
                //e表示el-switch的状态（true，false）
                //请求接口
                var falg = row.isMarketable === '1' ? 1 : 0
                axios.get('/findGoods/marketable?id=' + row.id + "&marketable=" + falg
                ).then((res) => {
                    if (res.data.flag) {
                        this.$message.success(res.data.message)
                    } else {
                        row.isMarketable = '0';
                        this.$message.error(res.data.message)
                    }

                })
            },
            changeSwitch(row) {
                var falg = row.status === '1' ? 1 : 0

                axios.get('/findGoods/aduit?id=' + row.id + "&status=" + falg
                ).then((res) => {
                    if (res.data.flag) {
                        this.$message.success(res.data.message)
                    } else {
                        this.$message.error(res.data.message)
                    }
                })
            }


        }
    })


</script>
</html>